import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader stdin = 
	            new BufferedReader(
	                new InputStreamReader(System.in));
	    int ans, len, i, j;
	    char ch, pre;
	    pre = 'A'-1;
	    while( true ) {
	    	String line = stdin.readLine();
	    	len = line.length();
	    	if (line.charAt(0)=='#' && len==1) break;
	    	ans = 0;
	    	for (i=0, j=1; i<len; ++i, ++j)
	    	{
	    		ch = line.charAt(i);
	    		if (ch>='A' && ch<='Z')
	    			ans += j*(int)(ch-pre);
	    	}
	    	System.out.println(ans);		
	    }
	}
}

